from bs4 import BeautifulSoup

soup = BeautifulSoup(open('bs4练习.html', encoding='utf-8'), 'lxml')
# 找到第一个li标签
# print(soup.li)
# # 根据条件找标签
# print(soup.find('li', class_='item-0'))
# 查找所有li标签,多个标签的情况下把标签放在列表里
# 需要限制数量就加上limit参数
# find_all = soup.find_all('li')
# for e in find_all:
#     print(e)
# 标签选择器
# select = soup.select('nav')
# print(select)
# # 属性选择器
# select = soup.select('li[class="item-0"]')
# print(select)
# # 类选择器
# select = soup.select('.post')
# # 后代选择器
# select = soup.select('div p')
# print(select)
# # 子代选择器
# select = soup.select('nav > ul > li')
# print(select)
# 获取节点的文本内容
li_texts = [li.get_text(strip=True) for li in soup.select('li')]
print(li_texts)
